/**
 * $ node argv.js one two three four five
[ 'node',
  '/home/avian/argvdemo/argv.js',
  'one',
  'two',
  'three',
  'four',
  'five' ]

var myArgs = process.argv.slice(2);
console.log('myArgs: ', myArgs);
  
 */

const { Builder, By, Key, until } = require('selenium-webdriver');
//引用浏览器
// const edge = require('selenium-webdriver/edge');
// const ie = require('selenium-webdriver/ie');
// const firefox = require('selenium-webdriver/firefox');
//如果是下载到某个盘路径存储 则使用下面方法
// const chrome = require('selenium-webdriver/chrome');

// const opera = require('selenium-webdriver/opera');
//ie和edge
// let ie_service = new ie.ServiceBuilder("/path/to/IEDriverServer.exe");
// let edge_service = new edge.ServiceBuilder("/path/to/msedgedriver.exe");
//火狐
// const options = new firefox.Options();
// options.setBinary("/path/to/geckodriver");

// 
(async function example() {
    //如果是内置安装的就使用这种方法
    let chrome = await new Builder().forBrowser('chrome').build();
    //谷歌驱动  //如果是下载到某个盘路径存储 则使用下面方法
    // chrome.setDefaultService(new chrome.ServiceBuilder('chromedriver.exe').build());
    // let Edge = await new Builder().setEdgeService(service).forBrowser('MicrosoftEdge').build();
    // let Ie = await new Builder().forBrowser('internet explorer').build();
    // let Opera = await new Builder().forBrowser('opera').build();
    // let Safari = await new Builder().forBrowser('safari').build();


    try {
        await chrome.manage().window().minimize();
        // await chrome.manage().window().setRect({ width: 0, height: 0 });
        // Navigate to Url
        await chrome.get('https://item.jd.com/54881560400.html');

        // let css = Chrome.findElement(By.css('#cheese '))
        // let cheddar = cheese.findElement(By.id('cheddar'));
        // Enter text "cheese" and perform keyboard action "Enter"
        // let elements = Chrome.findElement(By.class('price'));
        // let element = chrome.findElement({ class: 'price' });


        let element = await chrome.wait(until.elementLocated(By.className('price')), 1000);

        console.log(await element.getAttribute('textContent'));
        return await element.getAttribute('textContent');
        //如果返回不行可通过 写出到文件进行通讯
        // const fs = require('fs')
        // fs.writeFile('文件.txt', 'Node.js 中文网', 'utf8',(err) => {
        // if (err) throw err;
        //     console.log('文件已被保存');
        // });
    } finally {
        chrome.quit();
    }
})();